package com.sk.myview;

import com.sk.water.R;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class DataInput extends LinearLayout {
	public static final int NUMBER = 0;
	public static final int STRING = 1;
	private int configid;
	
	public DataInput(Context context) {
		super(context);
		LayoutInflater.from(context).inflate(R.layout.date_input, this);
	}
	
	public DataInput(Context context, AttributeSet attributeSet) {
		super(context,attributeSet);
		LayoutInflater.from(context).inflate(R.layout.date_input, this);
	}

	public void setConfigID(int id){
		configid = id;
	}
	public int getConfigID(){
		return configid;
	}
	public void setName(String name) {
		TextView dataName = (TextView) findViewById(R.id.data_input_name);
		dataName.setText(name);
	}

	public void setUnit(String unit) {
		TextView dataUnit = (TextView) findViewById(R.id.data_input_unit);
		dataUnit.setText(unit);
	}

	public String getDataValue() {
		EditText dataValue = (EditText) findViewById(R.id.data_input_edittext);
		return dataValue.getText().toString();
	}
	public void setType(int type){
		EditText editText = (EditText) findViewById(R.id.data_input_edittext);
		if(type == DataInput.NUMBER){
			editText.setInputType(EditorInfo.TYPE_CLASS_PHONE);
		}else if (type==DataInput.STRING) {
			editText.setInputType(EditorInfo.TYPE_CLASS_TEXT);
		}
	}
}
